package com.design.movieticket.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.design.movieticket.common.base.constant.Result;
import com.design.movieticket.common.base.constant.ResultStatus;
import com.design.movieticket.common.dto.XPage;
import com.design.movieticket.entity.Movie;
import com.design.movieticket.entity.Movie;
import com.design.movieticket.service.MovieService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

@Slf4j
@Api(tags = "电影模块")
@RestController
@RequestMapping("/movie")
public class MovieController {
    @Resource
    private MovieService movieService;

    /** 分页查询 */
    @ApiOperation("电影信息分页展示")
    @GetMapping("/list/page")
    public Result findMovieListByPage(Movie movie, XPage<Void> page) {
        IPage<Movie> MovieList = movieService.page(XPage.toIPage(page), movieService.buildQuery(movie));
        return new Result(MovieList,ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    /** 新增或更新电影数据 */
    @ApiOperation("新增或更新电影数据")
    @PostMapping("/addOrUpdate")
    public Result addOrEditMovie(Movie movie) {
        movieService.addOrUpdateMovieInfo(movie);
        return new Result(ResultStatus.SAVE_SUCCESS.getMsg(),ResultStatus.SAVE_SUCCESS.getCode());
    }

    /** 获取电影信息 */
    @ApiOperation("获取电影信息详情")
    @GetMapping("/getMovieDetail/{id}")
    public Result getMovieDetail(@PathVariable long id){
        return new Result(movieService.getMovieDetail(id),ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    /** 删除电影信息 */
    @ApiOperation("删除电影信息")
    @PostMapping("/delMovieById/{id}")
    public Result delMovieById(@PathVariable long id){
        movieService.delMovieById(id);
        return new Result(ResultStatus.DELETE_SUCCESS.getMsg(),ResultStatus.DELETE_SUCCESS.getCode());
    }





    /** 小程序获取热映影片列表 */
    @GetMapping("/wxGetMovieListForHot")
    public Result wxGetMovieListForHot(){
        return new Result(movieService.wxGetMovieListForHot(),ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    /** 小程序获取即将上映影片列表 */
    @GetMapping("/wxGetMovieListForFuture")
    public Result wxGetMovieListForFuture(){
        return new Result(movieService.wxGetMovieListForFuture(),ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    /** 小程序根据影院id获取影片列表 */
    @GetMapping("/wxGetMovieListByCinemaId")
    public Result wxGetMovieListByCinemaId(Long cinemaId){
        return new Result(movieService.wxGetMovieListByCinemaId(cinemaId),ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }
}
